package com.mugu.ipclient;

import java.io.UnsupportedEncodingException;

/*
 ## CMD packet format
 # +----------------------+-----------------------+-------------------------+-----------------------+
 # | (2) Banner(0x2382)   | (1) Command           | (4) Result              | (4) unused_1(const:0) |
 # | (4) Len1             | (Len1) Str_1/userid   | (4) Len2                | (Len2) Str_2/passwd   |
 # | (4) Len3             | (Len3) Str_3/mac addr | (4) Key                 | (4) unused_2(const:0) |
 # | (4) resv(0x3ff00000) | (4) Len4              | (Len4) Str_4/result msg |                       |
 # +----------------------+-----------------------+-------------------------+-----------------------+
 */
class CMDPacketModel {

	private final short banner = 0x2382;
	private byte command;
	private int result;
	private final int unused1 = 0;
	private int len1;
	private String str1;
	private int len2;
	private String str2;
	private int len3;
	private String str3;
	private int key;
	private final int unused2 = 0;
	private final int resv = 0x3ff00000;
	private int len4;
	private String str4;

	public CMDPacketModel() {

	}

	public CMDPacketModel(byte command, int result, String str1, String str2,
			String str3, String str4, int key) {
		this.command = command;
		this.result = result;

		this.str1 = str1;
		this.str2 = str2;
		this.str3 = str3;
		this.key = key;
		this.str4 = str4;
		try {
			this.len1 = str1.getBytes("gbk").length;
			this.len2 = str2.getBytes("gbk").length;
			this.len3 = str3.getBytes("gbk").length;
			this.len4 = str4.getBytes("gbk").length;
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
	}

	public short getBanner() {
		return banner;
	}

	public int getUnused1() {
		return unused1;
	}

	public int getUnused2() {
		return unused2;
	}

	public int getResv() {
		return resv;
	}

	public byte getCommand() {
		return command;
	}

	public void setCommand(byte command) {
		this.command = command;
	}

	public int getResult() {
		return result;
	}

	public void setResult(int result) {
		this.result = result;
	}

	public int getLen1() {
		return len1;
	}

	public void setLen1(int len1) {
		this.len1 = len1;
	}

	public String getStr1() {
		return str1;
	}

	public void setStr1(String str1) {
		this.str1 = str1;
	}

	public int getLen2() {
		return len2;
	}

	public void setLen2(int len2) {
		this.len2 = len2;
	}

	public String getStr2() {
		return str2;
	}

	public void setStr2(String str2) {
		this.str2 = str2;
	}

	public int getLen3() {
		return len3;
	}

	public void setLen3(int len3) {
		this.len3 = len3;
	}

	public String getStr3() {
		return str3;
	}

	public void setStr3(String str3) {
		this.str3 = str3;
	}

	public int getKey() {
		return key;
	}

	public void setKey(int key) {
		this.key = key;
	}

	public int getLen4() {
		return len4;
	}

	public void setLen4(int len4) {
		this.len4 = len4;
	}

	public String getStr4() {
		return str4;
	}

	public void setStr4(String str4) {
		this.str4 = str4;
	}

	@Override
	public String toString() {
		return "CMDPacketModel [banner=0x" + Integer.toHexString(banner)
				+ ", command=0x" + Integer.toHexString(command) + ", result=0x"
				+ Integer.toHexString(result) + ", unused1=" + unused1
				+ ", len1=" + len1 + ", str1=" + str1 + ", len2=" + len2
				+ ", str2=" + str2 + ", len3=" + len3 + ", str3=" + str3
				+ ", key=" + key + ", unused2=" + unused2 + ", resv=0x"
				+ Integer.toHexString(resv) + ", len4=" + len4 + ", str4="
				+ str4 + "]";
	}
}